﻿using System;
using UnityEngine;
using UnityEngine.Networking;

// Token: 0x0200030E RID: 782
public abstract class MicroNPC : Micro
{
	// Token: 0x060013C7 RID: 5063 RVA: 0x00083FFC File Offset: 0x000821FC
	protected override void Awake()
	{
		base.Awake();
		this.baseHeight = 1.6f;
		base.gameObject.AddComponent<MicroObstacleDetector>();
		LODGroup lodgroup = base.gameObject.GetComponent<LODGroup>();
		if (lodgroup == null)
		{
			lodgroup = base.gameObject.AddComponent<LODGroup>();
			lodgroup.SetLODs(new LOD[]
			{
				new LOD(0.005f, base.GetRenderers())
			});
		}
		base.movement.tileWidth = 0.6f;
		this.lockedScale = base.transform.lossyScale.y;
		if (GlobalPreferences.MicroAI.value)
		{
			this.ai.EnableAI();
		}
	}

	// Token: 0x060013C8 RID: 5064 RVA: 0x000840B8 File Offset: 0x000822B8
	protected override void OnDestroy()
	{
		UnityEngine.Object.Destroy(base.GetComponent<MicroObstacleDetector>());
		UnityEngine.Object.Destroy(base.GetComponent<LODGroup>());
		UnityEngine.Object.Destroy(base.GetComponent<MovementCharacter>());
		if (this.shooterController != null)
		{
			UnityEngine.Object.Destroy(this.shooterController);
		}
		base.OnDestroy();
	}

	// Token: 0x060013C9 RID: 5065 RVA: 0x00084108 File Offset: 0x00082308
	public override void Crush(EntityBase entity, Micro.CollisionData collisionData)
	{
		if (!GlobalPreferences.CrushNpcEnabled.value && !this.isPlayer)
		{
			return;
		}
		this.lockedScale = base.transform.lossyScale.y;
		base.movement.enabled = false;
		this.ai.enabled = false;
		if (this.shooterController)
		{
			this.shooterController.UnequipGun();
		}
		base.Crush(entity, collisionData);
	}

	// Token: 0x060013CA RID: 5066 RVA: 0x00084184 File Offset: 0x00082384
	public override void StandUp()
	{
		base.movement.enabled = true;
		this.ai.enabled = true;
		base.StandUp();
	}

	// Token: 0x060013CB RID: 5067 RVA: 0x00002973 File Offset: 0x00000B73
	public void OnGrabbedByHand()
	{
	}

	// Token: 0x060013CC RID: 5068 RVA: 0x000841A4 File Offset: 0x000823A4
	public override void OnStartAuthority()
	{
		if (this != null)
		{
			ObjectManager.Instance.OnMicroNPCSpawned(this);
		}
	}

	// Token: 0x060013CD RID: 5069 RVA: 0x000841C0 File Offset: 0x000823C0
	private void Update()
	{
		if (this.lockedScale != base.transform.lossyScale.y)
		{
			if ((!this.isDead && base.transform.parent) || (base.IsStuck() && ((!GlobalPreferences.StuckMicroGrows.value && this.lockedScale < base.transform.lossyScale.y) || (!GlobalPreferences.StuckMicroShrinks.value && this.lockedScale > base.transform.lossyScale.y))))
			{
				base.StayAtLockedScale(base.transform, this.lockedScale);
			}
		}
		else
		{
			this.lockedScale = base.transform.lossyScale.y;
		}
		if (!base.isCrushed)
		{
			Quaternion b = Quaternion.FromToRotation(base.transform.up, Vector3.up) * base.transform.rotation;
			base.transform.rotation = Quaternion.Slerp(base.transform.rotation, b, Time.deltaTime * 3f);
		}
	}

	// Token: 0x060013CE RID: 5070 RVA: 0x000842FA File Offset: 0x000824FA
	private void AddShooterController()
	{
		this.shooterController = base.gameObject.AddComponent<AIShooterController>();
	}

	// Token: 0x060013CF RID: 5071 RVA: 0x0008430D File Offset: 0x0008250D
	public AIShooterController GetShooterController(bool createIfNecessary)
	{
		if (this.shooterController == null && createIfNecessary)
		{
			this.AddShooterController();
		}
		return this.shooterController;
	}

	// Token: 0x060013D0 RID: 5072 RVA: 0x00084332 File Offset: 0x00082532
	public void EquipRaygun()
	{
		if (this.shooterController == null)
		{
			this.AddShooterController();
		}
		this.shooterController.EquipRaygun();
	}

	// Token: 0x060013D1 RID: 5073 RVA: 0x00084356 File Offset: 0x00082556
	public void EquipSMG()
	{
		if (this.shooterController == null)
		{
			this.AddShooterController();
		}
		this.shooterController.EquipSMG();
	}

	// Token: 0x060013D2 RID: 5074 RVA: 0x0008437A File Offset: 0x0008257A
	public void UnequipGun()
	{
		if (this.shooterController)
		{
			this.shooterController.UnequipGun();
		}
	}

	// Token: 0x060013D3 RID: 5075 RVA: 0x00002973 File Offset: 0x00000B73
	private void UNetVersion()
	{
	}

	// Token: 0x060013D4 RID: 5076 RVA: 0x00084398 File Offset: 0x00082598
	public override bool OnSerialize(NetworkWriter writer, bool forceAll)
	{
		bool flag = base.OnSerialize(writer, forceAll);
		bool flag2;
		return flag2 || flag;
	}

	// Token: 0x060013D5 RID: 5077 RVA: 0x000843B1 File Offset: 0x000825B1
	public override void OnDeserialize(NetworkReader reader, bool initialState)
	{
		base.OnDeserialize(reader, initialState);
	}

	// Token: 0x04001711 RID: 5905
	private float lockedScale;

	// Token: 0x04001712 RID: 5906
	protected AIShooterController shooterController;
}
